home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / tool chest / testing & debugging / synccatch 2.1 / read me
Encoding:
Text File  |  1999-11-19  |  7.5 KB  |  122 lines

  1. SyncCatch
  2.  
  3. version 2.1
  4. by Jim Luther
  5. Copyright © 1997-1999 Apple Computer, Inc.
  6. All rights reserved.
  7.  
  8. What is SyncCatch?
  9.  
  10. SyncCatch is a debugging tool that catches synchronous File Manager and Device Manager requests made from code running as the result of an interrupt. If it catches one of these illegal synchronous requests, it drops into MacsBug with a message.
  11.  
  12. Why are synchronous File Manager and Device Manager requests made at interrupt time illegal?
  13.  
  14. Synchronous File Manager and Device Manager requests made at interrupt time can deadlock or crash the system. See the develop magazine article “Asynchronous Routines on the Macintosh” in issue 13 if you’d like more detailed information.
  15.  
  16. SyncCatch catches requests made at interrupt time with system patches that. The patches check for four conditions to determine if the request was made at interrupt time:
  17.  
  18. 1. The 68K interrupt level. If the interrupt level is not zero, then interrupts are disabled and synchronous requests should be made.
  19.  
  20. 2. VBL tasks are executing. The Mac OS executes VBL tasks at interrupt level zero. However, VBL tasks execute as a result of an interrupt so synchronous requests are still illegal.
  21.  
  22. 3. Deferred Task Manager tasks are executing. The Mac OS executes Deferred Task Manager tasks at interrupt level zero. However, Deferred Task Manager tasks execute at interrupt time so synchronous requests are still illegal.
  23.  
  24. 4. Secondary Interrupt Handlers are executing. The Mac OS executes Secondary Interrupt Handlers at interrupt level zero. However, Secondary Interrupt Handlers execute at interrupt time so synchronous requests are still illegal.
  25.  
  26. What should I do when SyncCatch drops into MacsBug with a message?
  27.  
  28. If it happened to me, I’d want to find out what code was making the illegal request. That way, I could tell the publisher of that code to fix the problem, or if it were my code, I could fix it before someone caught me crashing the system.
  29.  
  30. Here’s some hints you can use to find the faulty code:
  31.  
  32. 1. First look at SyncCatch’s message. It’ll tell you if the illegal request was a File Manager or Device Manager request. It’ll also tell you why the synchronous request shouldn’t have been made (interrupts disabled, executing VBL tasks, executing Deferred Tasks, or executing Secondary Interrupt Handlers).
  33.  
  34. 2. Look at the parameter block passed to the request using MacsBug’s DM command and the appropriate memory template. I usually start with the IOParamBlockRec template because it's pretty generic.
  35.  
  36. You type this:
  37.  
  38.     DM RA0 IOParamBlockRec
  39.  
  40. MacsBug shows you something like this:
  41.  
  42.  Displaying IOParamBlockRec at 000003A4
  43.   000003A4  qLink              NIL
  44.   000003A8  qType              0002 = ioQType 
  45.   000003AA  ioTrap             A005 _Status 
  46.   000003AC  ioCmdAddr          001AD512 ->  
  47.   000003B0  ioCompletion       NIL 
  48.   000003B4  ioResult           FFEE 
  49.   000003B6  ioNamePtr          NIL
  50.   000003BA  ioVRefNum          0008 = Guts 
  51.   000003BC  ioRefNum           FFCA = .ATADisk 
  52.   000003BE  ioVersNum          #0 
  53.   000003BF  ioPermssn          #43 
  54.   000003C0  ioMisc             666C7573 is a bad pointer 
  55.   000003C4  ioBuffer           00214A20 ->  
  56.   000003C8  ioReqCount         00001000 
  57.   000003CC  ioActCount         00001000 
  58.   000003D0  ioPosMode          0001 = fsFromStart 
  59.   000003D2  ioPosOffset        05883000 
  60.   000003D6  ioWPosOffset.lo    5E8CC000
  61.  
  62. MacsBug will show you the parameter block used to make the request. SyncCatch sets up the ioTrap field the same way the File and Device Managers do, so MacsBug will show you what request was made by name.
  63.  
  64. 3. Stack crawl using MacsBug’s SC7 command to find out what code called the File Manager or Device Manager.
  65.  
  66. If you’re lucky, it’ll be in code you wrote but haven’t shipped. If not, then you’ll have to look further to figure out what code made the illegal request.
  67.  
  68. Note: If register A0 contains $03A4 (as shown in the example above), then the driver request is being made in response to a File Manager request. You can find out what File Manager request was made by looking at the request at the head of the File Manager request queue ($0362). You type this:
  69.  
  70.     DM 362^ IOParamBlockRec
  71.  
  72. MacsBug shows you something like this:
  73.  
  74.  Displaying IOParamBlockRec at 074249EA
  75.   074249EA  qLink              NIL
  76.   074249EE  qType              0005 = fsQType 
  77.   074249F0  ioTrap             0209 = PBGetCatInfoSync 
  78.   074249F2  ioCmdAddr          001AEE5A ->  
  79.   074249F6  ioCompletion       NIL 
  80.   074249FA  ioResult           0001 
  81.   074249FC  ioNamePtr          0744AA72 -> "SyncCatch.tdm" 
  82.   07424A00  ioVRefNum          FFFF = Guts 
  83.   07424A02  ioRefNum           0000 
  84.   07424A04  ioVersNum          #0 
  85.   07424A05  ioPermssn          #0 
  86.   07424A06  ioMisc             00030200 ->  
  87.   07424A0A  ioBuffer           54444154 is a bad pointer 
  88.   07424A0E  ioReqCount         43574945 
  89.   07424A12  ioActCount         01000000 
  90.   07424A16  ioPosMode          0000 = fsAtMark 
  91.   07424A18  ioPosOffset        00000001 
  92.   07424A1C  ioWPosOffset.lo    245B0000 
  93.  
  94. In this case, the File Manager request that caused the synchronous device Read was a synchronous PBGetCatInfo request.
  95.  
  96. Can I leave SyncCatch installed all of the time? How much does it slow my system down?
  97.  
  98. You can leave SyncCatch installed all of the time -- it shouldn’t affect performance much and from my testing with Mac OS 7.6, it looks like there is nothing in the Mac OS system code making illegal synchronous requests. Worst case, the patch code adds around sixty 68K instructions to every File Manager request and to _Read, _Write, _Control, and _Status requests made to device drivers.
  99.  
  100. I installed SyncCatch and during the icon parade, its icon is X'd out. How come?
  101.  
  102. You probably don’t have MacsBug installed. SyncCatch won’t install if there’s no low-level debugger present.
  103.  
  104. Is there anything you know of that sets off SyncCatch?
  105.  
  106. Yes, using the “Force Quit” key sequence (command-option-escape) or using MacsBug’s ES command at interrupt time will set off SyncCatch because they both call ExitToShell. ExitToShell closes any files opened by the application and closes the application file. The _Close calls to the File Manager are synchronous and since they’re made at interrupt time, SyncCatch will catch them. In general, force quitting an application should only be done if the application has hung or crashed, and then, you should probably restart your system as soon as possible because ExitToShell performs all sorts of things that should really only be done at non-interrupt time.
  107.  
  108. Is there an easy way to set break points with MacsBug on code that shouldn't be called at interrupt time?
  109.  
  110. Yes, get the latest MacsBug (version 6.6 or later) and use the built in TaskLevel expression. TaskLevel will resolve to zero if it is not interrupt time. For example, if you found that PBGetCatInfoSync was being called at interrupt time and wanted to catch the code making the PBGetCatInfoSync call, you could set both an ATrap break and a TVector Break to catch that by typing this in MacsBug:
  111.  
  112. APIB PBGetCatInfoSync TaskLevel!=0
  113.  
  114. (APIB is a macro that sets both the ATrap and TVector break for a specified routine.)
  115.  
  116. The bits in TaskLevel are defined in the public interface Debugging.h. TaskLevel is available for use within programs starting with Mac OS 9.0.
  117.  
  118. Revision History
  119.  
  120. 1.0    First release
  121. 2.0    Added checks for secondary interrupt handler execution time.
  122. 2.1    Fixed check for secondary interrupt handler (SyncCatch would sometimes give false positives and say secondary interrupt handlers were running when they weren't). Updated the Read Me to include more debugging tips.